import { computed, ref, unref } from 'vue';
import { Table } from 'ant-design-vue';

export default () => {
  const selectedRowKeys = ref<string[]>([]);

  const onSelectChange = (changableRowKeys: string[]) => {
    selectedRowKeys.value = changableRowKeys;
  };

  const rowSelection = computed(() => ({
    selectedRowKeys: unref(selectedRowKeys),
    onChange: onSelectChange,
    hideDefaultSelections: true,
    selections: [
      Table.SELECTION_ALL,
      Table.SELECTION_INVERT,
      Table.SELECTION_NONE,
    ],
  }));

  return { selectedRowKeys, onSelectChange, rowSelection };
};
